package cn.com.unionlife.hy.system.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.com.unionlife.hy.core.controller.BaseController;
import cn.com.unionlife.hy.core.exception.BusinessException;
import cn.com.unionlife.hy.system.service.OrgQryService;
import cn.com.unionlife.hy.system.vo.OrgVO;
import cn.com.unionlife.hy.system.vo.UserVO;

@Controller
public class OrgController extends BaseController {

	@Resource(name = "orgQryService")
	private OrgQryService orgQryService;

	/**
	 * 该组织机构和下级组织选择器
	 * 
	 * @param id
	 * @return
	 * @throws BusinessException
	 */
	@RequestMapping(value = "/system/orgselector")
	public String goOrgSelector(
			HttpServletRequest request,
			@RequestParam(required = false, value = "name") String name,
			@RequestParam(value = "admin", defaultValue = "false") boolean admin,
			Model model) throws BusinessException {
		UserVO loginedUser = getLoginedUser(request);
		if (loginedUser != null) {
			model.addAttribute("orgs",orgQryService.getUserAuthorizedOrg(loginedUser.getUm_user_id() , name , admin , true));
		}
		return "system/orgSelector";
	}

}
